
jQuery(document).ready(function () {
    //页面初始化
    EgiMainPage.init();
});

var EgiMainPage = function () {

    var initChartOrder1=function(){
        var dom = document.getElementById("dashboard_chart_order_1");
        var myChart = echarts.init(dom);
        //图例
        var categories = [
            { name: "回款金额", ctype: "huikuan", tColor: "#2AB4C0" },
            { name: "签单金额", ctype: "qiandan", tColor: "#E08283" },
        ];
        //得到图例颜色
        function getCategoryColors() {
            var colors = [];
            for (i = 0; i < categories.length; i++) {
                element = categories[i];
                colors.push(element.tColor);
            }
            return colors;
        }
    
        var option = {
            // title: {
            //     text: '七年业绩分析',
            //     subtext: '纯属虚构'
            // },
            tooltip: {
                trigger: 'axis'
            },
            color: getCategoryColors(),
            legend: {
                data:['签单金额','回款金额'],
                left:5
            },
            toolbox: {
                show: true,
                feature: {
                    // dataZoom: {
                    //     yAxisIndex: 'none'
                    // },
                    // dataView: {readOnly: false},
                    magicType: {type: ['line', 'bar']},
                    restore: {},
                    saveAsImage: {}
                }
            },
            xAxis:  {
                type: 'category',
                // boundaryGap: false,
                data: ['2013','2014','2015','2016','2017','2018','2019'],
                axisLabel: {
                    formatter: '{value}年'
                }
            },
            yAxis: {
                type: 'value',
                axisLabel: {
                    formatter: '{value}万'
                }
            },
            series: [
                {
                    name:'签单金额',
                    type:'bar',
                    data:[1200, 1150, 1500, 1300, 1200, 1300, 1000],
                    markPoint: {
                        data: [
                            {type: 'max', name: '最大值'},
                            {type: 'min', name: '最小值'}
                        ]
                    },
                    markLine: {
                        data: [
                            {type: 'average', name: '平均值'}
                        ]
                    }
                },
                {
                    name:'回款金额',
                    type:'bar',
                    data:[900, 810, 1100, 1000, 1150, 900, 850],
                    markPoint: {
                        data: [
                            {name: '最低', value: 810, xAxis: 1, yAxis: 820}
                        ]
                    },
                    markLine: {
                        data: [
                            {type: 'average', name: '平均值'},
                            [{
                                symbol: 'none',
                                x: '95%',
                                yAxis: 'max'
                            }, {
                                symbol: 'circle',
                                label: {
                                    normal: {
                                        position: 'start',
                                        formatter: '最高'
                                    }
                                },
                                type: 'max',
                                name: '最高点'
                            }]
                        ]
                    }
                }
            ]
        };

        
        myChart.setOption(option);

    }
    var initChartOrder2=function(){
        var dom = document.getElementById("dashboard_chart_order_2");
        var myChart = echarts.init(dom);
        //图例
        var categories = [
            { name: "回款金额", ctype: "huikuan", tColor: "#2AB4C0" },
            { name: "签单金额", ctype: "qiandan", tColor: "#E08283" },
        ];
        //得到图例颜色
        function getCategoryColors() {
            var colors = [];
            for (i = 0; i < categories.length; i++) {
                element = categories[i];
                colors.push(element.tColor);
            }
            return colors;
        }
    
        var option = {
            // title: {
            //     text: '七年业绩分析',
            //     subtext: '纯属虚构'
            // },
            tooltip: {
                trigger: 'axis'
            },
            color: getCategoryColors(),
            legend: {
                data:['签单金额','回款金额'],
                left:5
            },
            toolbox: {
                show: true,
                feature: {
                    // dataZoom: {
                    //     yAxisIndex: 'none'
                    // },
                    // dataView: {readOnly: false},
                    magicType: {type: ['line', 'bar']},
                    restore: {},
                    saveAsImage: {}
                }
            },
            xAxis:  {
                type: 'category',
                boundaryGap: false,
                data: ['1','2','3','4','5','6','7','8','9','10','11','12'],
                axisLabel: {
                    formatter: '{value}月'
                }
            },
            yAxis: {
                type: 'value',
                axisLabel: {
                    formatter: '{value}万'
                }
            },
            series: [
                {
                    name:'签单金额',
                    type:'line',
                    data:[230,185,  250, 120, 110, 120,  230],
                    markPoint: {
                        data: [
                            {type: 'max', name: '最大值'},
                            {type: 'min', name: '最小值'}
                        ]
                    },
                    markLine: {
                        data: [
                            {type: 'average', name: '平均值'}
                        ]
                    }
                },
                {
                    name:'回款金额',
                    type:'line',
                    data:[92,95,115, 81,  180, 90,  100],
                    markPoint: {
                        data: [
                            {name: '最低', value: 81, xAxis: 3, yAxis: 82}
                        ]
                    },
                    markLine: {
                        data: [
                            {type: 'average', name: '平均值'},
                            [{
                                symbol: 'none',
                                x: '95%',
                                yAxis: 'max'
                            }, {
                                symbol: 'circle',
                                label: {
                                    normal: {
                                        position: 'start',
                                        formatter: '最高'
                                    }
                                },
                                type: 'max',
                                name: '最高点'
                            }]
                        ]
                    }
                }
            ]
        };

        
        myChart.setOption(option);

    }
    
    var dataTreeProdLibWorkshop = [
        {"text": "电梯",
        "children": [
            {"text": "公共逻辑库",
            "children": [
                {"text": "整梯验算",}, 
            ]}, 
            {"text": "虚拟件APVP库",
            "children": [
                {"text": "机械部件",
                "children": [
                    {"text": "机房部件"}, 
                    {"text": "轿箱部件"}, 
                    {"text": "对重部件"}, 
                    {"text": "轿架部件"}, 
                ]}, 
            ]}, 
            {"text": "机械部件",
            "children": [
                {"text": "机房部件",
                "children": [
                    {"text": '曳引机'}, 
                    {"text": "基座"}, 
                    {"text": "钢梁"}, 
                    {"text": "..."}, 
                ]}, 
                {"text": "轿箱部件"}, 
                {"text": "对重部件"}, 
                {"text": "轿架部件"}, 
            ]}, 
        ]},
        {"text": "扶梯土建图",
            "children": [
                {"text": "机械部件"}, 
                {"text": "电器部件",
                "children": [
                    {"text": "控制柜"}, 
                ]}, 
            ]
        }, 
    ];

    var initJstree = function () {

        var _divIdMy = "#treeJsTreeProdLibWorkshop"
        $(_divIdMy).jstree({
            'plugins': ["types", "state", "dnd"],
            'core': { "themes" : {  "responsive": false },"check_callback" : true, 'data': dataTreeProdLibWorkshop, },
            "types" : { "default" : { "icon" : "fa fa-folder icon-state-success icon-lg" }},
            "state" : { "key" : "demo2" },
        }).bind("loaded.jstree", function (event, data) {  data.instance.open_all();  });

    }
    var initAgGrid = function () {

        WebEpdFileGcsAgGrid.initAgGridRoleList('myGridRoleList');

    }


    var initButton=function(){
        //mytesk
        $(".egi-mytask-order").click(function () {
            $(".egi-mainpage").hide();
            $(".egi-mainpage.egi-mainpage-mytask-order").show();
        });
        $(".egi-mytask-pcn").click(function () {
            $(".egi-mainpage").hide();
            $(".egi-mainpage.egi-mainpage-mytask-pcn").show();
        });
        $(".egi-mytask-pso").click(function () {
            $(".egi-mainpage").hide();
            $(".egi-mainpage.egi-mainpage-mytask-pso").show();
        });
        
        $(".egi-mytask-pud").click(function () {
            $(".egi-mainpage").hide();
            $(".egi-mainpage.egi-mainpage-mytask-pud").show();
        });
        //home
        $("#egi-mainpage-home").click(function () {
            $(".egi-mainpage").hide();
            $(".egi-mainpage.egi-mainpage-home").show();
        });
        //system manger
        $(".egi-sysm-workshop").click(function () {
            $(".egi-mainpage").hide();
            $(".egi-mainpage.egi-mainpage-sysm-workshop").show();
        });
        //user
        $("#egi-myProfile").click(function () {
            $(".egi-mainpage").hide();
            $(".egi-mainpage.egi-mainpage-myProfile").show();
        });
        $("#egi-myMessage").click(function () {
            $(".egi-mainpage").hide();
            $(".egi-mainpage.egi-mainpage-myMessage").show();
        });
    }


    var handleInit = function (params) {

        $(".egi-mainpage").hide();
        // $(".egi-mainpage.egi-mainpage-home").show();
        $(".egi-mainpage.egi-mainpage-sysm-workshop").show();

        initButton();        
        initJstree();
        initAgGrid();
        initChartOrder1();
        initChartOrder2();
    };
    

    return {
        init: function () {
            handleInit();
        },
    };
}();






